package com.aidex.biz.controller;

import com.aidex.biz.domain.JinjianCheckFiles;
import com.aidex.biz.service.JinjianCheckFilesService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 进件归档资料Controller
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/biz/bizJinjianCheckFiles")
public class JinjianCheckFilesController extends BaseController {
    @Autowired
    private JinjianCheckFilesService jinjianCheckFilesService;

    /**
     * 查询进件归档资料列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianCheckFiles:list')")
    @GetMapping("/list")
    public R<PageInfo> list(JinjianCheckFiles jinjianCheckFiles, HttpServletRequest request,
            HttpServletResponse response) {
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianCheckFiles.setCompanyId(null);
        } else {
            jinjianCheckFiles.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        jinjianCheckFiles.setPage(new PageDomain(request, response));
        return R.data(jinjianCheckFilesService.findPage(jinjianCheckFiles));
    }

    /**
     * 获取进件归档资料详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianCheckFiles:query')")
    @GetMapping(value = "/{id}")
    public R<JinjianCheckFiles> detail(@PathVariable("id") String id) {
        return R.data(jinjianCheckFilesService.get(id));
    }

    /**
     * 新增进件归档资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianCheckFiles:add')")
    @Log(title = "进件归档资料", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated JinjianCheckFiles jinjianCheckFiles) {
        return R.status(jinjianCheckFilesService.save(jinjianCheckFiles));
    }

    /**
     * 修改进件归档资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianCheckFiles:edit')")
    @Log(title = "进件归档资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated JinjianCheckFiles jinjianCheckFiles) {
        return R.status(jinjianCheckFilesService.save(jinjianCheckFiles));
    }


    /**
     * 删除进件归档资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianCheckFiles:remove')")
    @Log(title = "进件归档资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(jinjianCheckFilesService.deleteJinjianCheckFilesByIds(ids));
    }

    /**
     * 获取最大编号
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianCheckFiles:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort() {
        return R.data(jinjianCheckFilesService.findMaxSort(new JinjianCheckFiles()));
    }

    /**
     * 导出进件归档资料列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianCheckFiles:export')")
    @Log(title = "进件归档资料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(JinjianCheckFiles jinjianCheckFiles) {

        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianCheckFiles.setCompanyId(null);
        } else {
            jinjianCheckFiles.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        List<JinjianCheckFiles> list = jinjianCheckFilesService.findList(jinjianCheckFiles);
        ExcelUtil<JinjianCheckFiles> util = new ExcelUtil<JinjianCheckFiles>(JinjianCheckFiles.class);
        return util.exportExcel(list, "进件归档资料数据");
    }

}
